package com.yidu.InventoryManagement.controller;

import com.yidu.InventoryManagement.entity.CashStock;
import com.yidu.InventoryManagement.entity.TAStock;
import com.yidu.InventoryManagement.service.TAStockService;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 梁俊
 * @date 2022/12/9
 * &@version 1.0
 */
@RestController
//@Controller
public class TAStockControlller {
    @Resource
    public TAStockService taStockService;


    @RequestMapping("/selectTAStockk")
   // @ResponseBody
    public Map selectTAStockk(int page, int limit, String date){
        //判断时间是否为null
        if (date==null){
            date="";
        }
        //查询加分页selectTAStockk
        List<TAStock> cash = taStockService.selectTAStockk('%' + date + '%', page, limit);

        //查行数selectTAStockCount
        int count = taStockService.selectTAStockCount('%' + date + '%');
        System.out.println("行数"+count);
        //map集合
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",count);
        map.put("data",cash);
        return map;
    }


    //多个删除
    @RequestMapping("/deleteTaShockk")
    public int deleteTaShockk(String securityAccrualStockId){
        //删除方法deleteTaShockk
        int i = taStockService.deleteTaShockk(securityAccrualStockId);
        if(i>0){
            System.out.println("删除成功"+i);
        }else{
            System.out.println("删除失败"+i);
        }
        return i;
    }


    //添加
    @RequestMapping("/insertTaShockk")
    public int insertTaShockk(TAStock taStock){
        //查询数据库行数selectSecurityAccrualStockIdd
        int s1 = taStockService.selectSecurityAccrualStockIdd();
        //公共
        int i=0;
        //判断数据库行数==0
        if (s1==0){
            //TA库存对象 TA202302151，id库存手动填
            TAStock taStock1=new TAStock("TA202302151",taStock.getDate(),taStock.getInitialState(),taStock.getQuantity(),taStock.getMoney(),"统计库存",taStock.getFundId(),taStock.getRemarks());
             //ta库存数据添加
            i = taStockService.insertTaShockk(taStock1);
        }else{
            //获取最大id.su
            String s = taStockService.selectDaId().substring(2,11);
            //id自动增长类
            IdUtil idUtil=new IdUtil();
            //把获取的最大id放到id自动增长类 TA拼接
            String id = "TA"+idUtil.createID(s);
            //TA库存对象 获取的id库存手动填
            TAStock taStock1=new TAStock(id,taStock.getDate(),taStock.getInitialState(),taStock.getQuantity(),taStock.getMoney(),"统计库存",taStock.getFundId(),taStock.getRemarks());
             i = taStockService.insertTaShockk(taStock1);
        }

        if(i>0){
            System.out.println("添加成功"+i);
        }else{
            System.out.println("添加失败"+i);
        }
        return i;
    }


    //修改
    @RequestMapping("/updateTAStockk")
    public int updateTAStockk(TAStock taStock){
        //ta库存对象
      TAStock taStock1=new TAStock(taStock.getSecurityAccrualStockId(),taStock.getDate(),taStock.getInitialState(),taStock.getQuantity(),taStock.getMoney(),taStock.getRemark(),taStock.getFundId(),"");
       //放到修改的方法
        int i = taStockService.updateTAStockk(taStock1);
        if(i>0){
            System.out.println("修改成功"+i);
        }else{
            System.out.println("修改失败"+i);
        }
        return i;
    }


}



